/**
 * 日志工具 - 生产环境禁用console日志
 * 支持Node.js和浏览器环境
 */
const isDevelopment = process.env.NODE_ENV === 'development'

// 安全使用console（仅在可用时）
const safeConsole = {
  error: typeof console !== 'undefined' && console.error ? console.error.bind(console) : () => {},
  warn: typeof console !== 'undefined' && console.warn ? console.warn.bind(console) : () => {},
  log: typeof console !== 'undefined' && console.log ? console.log.bind(console) : () => {},
  info: typeof console !== 'undefined' && console.info ? console.info.bind(console) : () => {},
  debug: typeof console !== 'undefined' && console.debug ? console.debug.bind(console) : () => {}
}

export const logger = {
  error: (message, ...args) => {
    if (isDevelopment) {
      safeConsole.error(`[ERROR] ${message}`, ...args)
    }
    // 生产环境可以发送到错误收集服务
  },
  
  warn: (message, ...args) => {
    if (isDevelopment) {
      safeConsole.warn(`[WARN] ${message}`, ...args)
    }
  },
  
  log: (message, ...args) => {
    if (isDevelopment) {
      safeConsole.log(`[LOG] ${message}`, ...args)
    }
  },
  
  info: (message, ...args) => {
    if (isDevelopment) {
      safeConsole.info(`[INFO] ${message}`, ...args)
    }
  },
  
  debug: (message, ...args) => {
    if (isDevelopment) {
      safeConsole.debug(`[DEBUG] ${message}`, ...args)
    }
  }
}

export default logger
